package RabbitMQ;

import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * @Author sven
 *
 * https://blog.csdn.net/qq_34021712/article/details/72567801
 */
public class ConnectionUtil {

    private  static ConnectionFactory factory = new ConnectionFactory();


    public static Connection getConnection() throws IOException, TimeoutException {
        //创建连接工厂
        //设置RabbitMQ相关信息
        factory.setHost("101.132.71.17");
        factory.setPort(5672);
        factory.setUsername("root");
        factory.setPassword("123456");
        factory.setConnectionTimeout(20000);
        //创建一个新的连接
        return factory.newConnection();
    }
}
